﻿using MeetingRoomBooking.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace MeetingRoomBooking.Infrastructure.Data.Configurations;

public class BookingConfiguration : IEntityTypeConfiguration<Booking>
{
    public void Configure(EntityTypeBuilder<Booking> builder)
    {
        builder.HasKey(b => b.Id);
        builder.Property(b => b.StartDate).IsRequired();
        builder.Property(b => b.EndDate).IsRequired();
        builder.Property(b => b.Title).IsRequired();
        builder.Property(b => b.Description);

        builder.HasOne(b => b.User)
               .WithMany()
               .HasForeignKey(b => b.UserId);

        builder.HasOne(b => b.Room)
               .WithMany()
               .HasForeignKey(b => b.RoomId);

    }
}
